<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下拉菜单</title>
    <style>
        * {
            margin: 0;
            padding: 0;

        }
        ul {
            list-style: none;
        }
        ul.father {
            width: 340px;
            height: 30px;
            background: url('./imgs/bg.jpg') no-repeat;
            margin: 100px auto;
        }

        ul.father  li{
            float: left;
            width: 100px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            background: url('./imgs/libg.jpg') no-repeat;
            margin-left: 10px;
        }
        ul.son{
            display: none;
        }

        ul.son li {
            margin-left: 0;
        }

    </style>
    <script src="../lib/jquery-3.4.1.js"></script>
    <script>
        /* $(document).ready(function(){

        }) */

        $(function(){
           /*  $("#father > li").mouseenter(function(){
                $(this).children("ul").stop().show(1000);
            });
            $("#father > li").mouseleave(function(){
                $(this).children("ul").stop().hide(1000);
            }); */
            // 参数1 ： 鼠标经过时执行的函数
            // 参数2 ： 鼠标离开时执行的函数
           /*  $("#father > li").hover(function(){
                $(this).children("ul").stop().show(1000);
            },function(){
                $(this).children("ul").stop().hide(1000);
            }); */

            
            $("#father > li").hover(function(){
                $(this).children("ul").stop().toggle(1000);
            });

        });
    </script>
</head>
<body>
   <ul class="father" id="father">
       <li>
           一级标签
           <ul class="son">
               <li>二级标签</li>
               <li>二级标签</li>
               <li>二级标签</li>
           </ul>
       </li>
       <li>
           一级标签
           <ul class="son">
               <li>二级标签</li>
               <li>二级标签</li>
               <li>二级标签</li>
           </ul>
       </li>
       <li>
           一级标签
           <ul class="son">
               <li>二级标签</li>
               <li>二级标签</li>
               <li>二级标签</li>
           </ul>
       </li>
   </ul>
</body>
<script>
/*     var fatherUlLis = document.getElementsByClassName("father")[0].children;
    var sonUl = document.getElementsByClassName("son");
    for(var i = 0;i < fatherUlLis.length ;i++){
        fatherUlLis[i].index = i;
        fatherUlLis[i].onmouseover = function(){
            sonUl[this.index].style.display = "block";
        }
        fatherUlLis[i].onmouseout = function(){
            sonUl[this.index].style.display = "none";
        }
    } */


    // 面向对象写法
   /*  function List(id){
        this.lists=document.getElementById(id).children;
    }

    List.prototype.init = function(){
        var that = this;
        for(var i = 0;i<this.lists.length;i++){
            this.lists[i].onmouseover = function(){
                that.show(this.children[0]);
            }
            this.lists[i].onmouseout = function(){
                that.hidden(this.children[0]);
            }
        }
    }

    List.prototype.show = function(obj){
        obj.style.display="block";
    }

    List.prototype.hidden = function(obj){
        obj.style.display="none";
    }

    var list =new List("father");
    list.init(); */

</script>
</html>